package model.inter

import model.BlastView
import model.Enemy
import model.View
import java.awt.Rectangle


/**
 * 攻击的接口的逻辑；
 */
interface Attackable {

    //攻击力
    val attactPower:Int;

    val whoCreate:View;


    /**
     * 估计到的某一个对象的一个操作；
     */
    fun attack(sufferable: Sufferable):Boolean{


        //这里我们要做的一个操作就是判断一下是否发生了碰撞的操作；
        var blockViewRect = sufferable.getRect()

        var rect = getRect()

        val rectTop = rect.y;
        val rectDown = rect.y + rect.height;

        val rectLeft = rect.x;
        val rectRight = rect.x + rect.width;


        val blockRectTop = blockViewRect.y;
        val blockRectDown = blockViewRect.y + blockViewRect.height;
        val blockRectLeft = blockViewRect.x;
        val blockRectRight = blockViewRect.x + blockViewRect.width;

        //这里表是不发生碰撞；
        var isHit = when {
            rectTop >= blockRectDown -> false
            rectDown <= blockRectTop -> false
            rectLeft >= blockRectRight -> false
            rectRight <= blockRectLeft -> false
            else -> true
        }

        if (isHit) {

            println("$this $rect hit  $sufferable $blockViewRect");
        }


        return isHit
    }

    fun getRect(): Rectangle

    /**
     * 这里表示攻击成功；
     */
    fun notifyAttactSuccess();
}